//
//  ViewController.m
//  QMCXDriver
//
//  Created by Massimo on 2017/4/12.
//  Copyright © 2017年 Massimo. All rights reserved.
//

#import "RootViewController.h"
#import "BasicViewController.h"
#import "Root_HomeViewController.h"
#import "Root_MineViewController.h"
#import "Root_OrdersViewController.h"
#import "UINavigationBar+Awesome.h"
#define Nav_Color  LLColorRGB(30, 27, 40)
#define NorColor LLColorRGB(165, 164, 169)
#define SelColor LLColorRGB(0, 193, 110)
#define CoverColor LLColorRGB(55, 53, 61)
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor clearColor];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"";
    self.navigationItem.backBarButtonItem = backItem;
    [self settingViews];
    [self setupAllViewController];
    [self settingsChildVC];
    
}


- (void)settingViews{
    
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : LLColorRGB(0, 193, 110)}];
   
    
    
    //背景图片
    UIImage *bgImg = [UIImage imageNamed:@"bg_home_TableviewBG"];
    UIImageView *bgImgView = [[UIImageView alloc] initWithImage:bgImg];
    bgImgView.frame = self.view.bounds;
    bgImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:bgImgView];
    //状态栏背景色
    UIView *statusBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, QScreenWidth, 20)];
    statusBg.backgroundColor = LLColorRGB(30, 27, 40);
    [self.view addSubview:statusBg];
    
    //YZDisplayViewController contentView 的位置
    UIView *content = [self valueForKey:@"contentView"];
    __weak typeof(self) weakSelf = self;
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.right.bottom.equalTo(weakSelf.view);
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    self.navigationController.navigationBarHidden = YES;
    [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar lt_setBackgroundColor:LLColorRGB(30, 27, 40)];
    [self.navigationController.navigationBar lt_reset];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
}

 
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (void)settingsChildVC{
    
    [self setUpTitleEffect:^(UIColor *__autoreleasing *titleScrollViewColor, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor, UIFont *__autoreleasing *titleFont, CGFloat *titleHeight, CGFloat *titleWidth) {
        *titleScrollViewColor = Nav_Color;
        *norColor = NorColor;
        *selColor = SelColor;
        *titleFont = [UIFont systemFontOfSize:17];
    }];
    [self setUpCoverEffect:^(UIColor *__autoreleasing *coverColor, CGFloat *coverCornerRadius) {
        *coverColor = CoverColor;
        *coverCornerRadius = 16;
    }];
    
      
}

- (void)setupAllViewController{
    
    NSArray *child = @[@"Mine",@"Home",@"Orders"];
    NSArray *titls = @[@"我的",@"首页",@"历史订单"];
    int idx = 0;
    for (NSString *name in child) {
        NSString *storyboardId = [NSString stringWithFormat:@"Root_%@VC",name];
        BasicViewController *vc  =[[UIStoryboard storyboardWithName:name bundle:nil] instantiateViewControllerWithIdentifier:storyboardId];
 
        vc.title = titls[idx];
        
        [self addChildViewController:vc];
        idx++;
    }
    self.selectIndex = 1;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
